<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的消息</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/css.css" />
</head>
<style>
    [v-cloak] {
        display: none;
    }
</style>
<body>
    <div v-cloak id="wrap" class="flex-wrap flex-vertical bg">
        <header>
            <ul>
                <li class="active">
                    <i onclick="back()" class="icon iconfont icon-back"></i>
                    <span>公告列表</span>
                </li>
            </ul>
        </header>
        <div class="message fixed-header">
            <div class="message">
                <div class="message-list" @click="godetail(item.id)" v-for="(item,index) in list" :key="index">
                    <div class="message-list2l">
                        <p class="message-title">{{item.title}}</p>
                        <p class="message-data">{{item.createtime}}</p>
                    </div>
                    <div class="message-list2r">
                        <span class="icon iconfont icon-right"></span>
                    </div>
                </div>
                <div class="nolist" v-show="finished">
                    已经没有更多啦
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="../../aui/js/aui.js"></script>
<script src="../../script/vue2.js"></script>
<script src="../../script/vue-resource.min.js"></script>
<script src="../../script/common.js"></script>
<script type="text/javascript">
var vm = new Vue({
    el: "#wrap",
    data: {
        uid: '',
        page: 1,
        list: [],
        title: '我的供应',
        pageNumber: 0,
        loading: false, //控制上拉加载的加载动画
        finished: false, //控制在页面往下移动到底部时是否调用接口获取数据
        isLoading: false, //控制下拉刷新的加载动画
    },
    mounted: function() {
        var that = this;
        apiready = function() {
            that.getList(1)
            api.setStatusBarStyle({
                style: 'dark'
            });
            api.addEventListener({ name: 'scrolltobottom' }, function(ret, err) {
                // that.toDoRequest();
                that.onLoad2()
            });
        };
    },
    methods: {
        godetail:function(id){
            openWinto('details', 'details', id)
        },
        getList: function(type) {
            var that = this;
            showProgress();
            var token = $api.getStorage('userInfo').token
            var uid = $api.getStorage('userInfo').id
            api.ajax({
                url: ajaxRoute.gonggaolist,
                method: 'post',
                data: {
                    values: {
                        token: token,
                        page: that.page
                    }
                }
            }, function(res, err) {
                // alert(JSON.stringify(res));
                console.log(JSON.stringify(res));
                if (res.code == 1) {
                    api.hideProgress();
                    if (type == 2) {
                        api.refreshHeaderLoadDone()
                    }
                    if (res.data.length == 0) {
                        api.toast({ msg: '暂无内容', location: 'middle' });
                    }
                    that.list = res.data
                    // alert(JSON.stringify(that.list));
                } else {
                    api.hideProgress();
                    api.toast({ msg: res.msg, location: 'middle' });
                }
            });
        },
        //下拉刷新
        onRefresh: function() {
            setTimeout(function() {
                api.refreshHeaderLoadDone()
                window.location.reload();
            }, 1000);
        },
        onLoad2: function() {
            // 异步更新数据
            var that = this
            that.page++
            showProgress();
            var token = $api.getStorage('userInfo').token
            var uid = $api.getStorage('userInfo').id
            api.ajax({
                url: ajaxRoute.gonggaolist,
                method: 'post',
                data: {
                    values: {
                        token: token,
                        page: that.page
                    }
                }
            }, function(res, err) {
                if (res.code == 1) {
                    api.hideProgress();
                    var s = res.data
                    for (var i = 0; i < s.length; i++) {
                        that.list.push(s[i])
                    }
                    that.loading = false
                    if (res.data.length == 0) {
                        that.loading = false
                        that.finished = true
                    } else {
                        that.loading = false
                    }
                } else {
                    api.hideProgress();
                    api.toast({ msg: res.msg, location: 'middle' });
                }
            });
        },
    }
})
</script>
